package com.css.prompt.dto;

import java.time.LocalDate;
import java.util.List;

import com.css.prompt.dto.MyPromptDto.PromptTemplate.BestPractice;
import com.css.prompt.model.MyPrompt;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class MyPromptDto {
    private Long id;
    private String title;
    private String description;
    private String content;
    private String category;
    private String folder;
    private LocalDate date;
    private String author;
    private String roleName;
    private String email;
    private String version;
    private Boolean isLatest;
    private List<String> tags;

    @JsonSerialize(using = PromptTemplateSerializer.class)
    private PromptTemplate prompt_template;

    @Data
    public static class PromptTemplate {
        private String base;
        private String reuse_prefix;
        private BestPractice best_practice;

        @Data
        public static class BestPractice {
            private String selenium;
            private String playwright;
            private String both;
        }
    }

    public static MyPromptDto from(MyPrompt p) {
        PromptTemplate pt = new PromptTemplate();
        pt.setBase(p.getBase());
        pt.setReuse_prefix(p.getReusePrefix());

        BestPractice bp = new BestPractice();
        bp.setSelenium(p.getSelenium());
        bp.setPlaywright(p.getPlaywright());
        bp.setBoth(p.getBoth());

        pt.setBest_practice(bp);

        return new MyPromptDto(
                p.getId(),
                p.getTitle(),
                p.getDescription(),
                p.getContent(),
                p.getCategory(),
                p.getFolder(),
                p.getDate(),
                p.getAuthor(),
                p.getRoleName(),
                p.getEmail(),
                p.getVersion(),
                p.getIsLatest(),
                p.getTags(),
                pt
        );
    }
}
